#! /usr/bin/env python
# pyidvid

import sys
import os

from libtovid.opts import Option, Usage, parse
from libtovid.backend import mplayer, ffmpeg
from libtovid import log

# Command-line usage
usage = Usage('pyidvid [options] -files ...',
    Option('files', 'FILE[,FILE...]', [],
           """A list of multimedia video files to identify.""",
           required=True),

    Option('verbose', '[terse|normal|all]', 'normal',
           """Verbosity level. 'terse' prints short output suitable for
           parsing, and nothing else; 'normal' displays summarized stats
           in plain English; 'all' prints all output from subprocesses
           along with normal summary stats.""")
)

if __name__ == '__main__':

    options = parse(sys.argv)

    if 'files' not in options:
        print(usage)
        print("Please provide -files")
        sys.exit(1)

    files = options['files']
    if isinstance(files, str):
        files = [files]

    if 'verbose' in options:
        log.level = 'debug'

    for file in files:
        log.info("Identifying file: %s" % file)
        print
        print("According to mplayer:")
        print(mplayer.identify(file))
        print(' ')
        print("According to ffmpeg:")
        print(ffmpeg.identify(file))

